﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Linq;

namespace FakeMarketplace
{
    public class ToUpperCaseConverter:IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((string)value).ToUpper();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
	
	
	public class ComputeSizeConverter: IValueConverter
	{
		      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var split = ((string)value).Split(' ');
                  string maxWord="";
                  foreach(var word in split)
                      if(word.Length>maxWord.Length)
                          maxWord=word;

       
            double res = 0;
            TextBlock textb = new TextBlock() {FontFamily=new FontFamily("Segoe WP BLACK"), Text = maxWord.ToUpper() ,FontSize=133.33};
            while (textb.ActualWidth > 420)
                --textb.FontSize;

            res = textb.FontSize;
                
           
            if (!String.IsNullOrEmpty((string)parameter))
            {

                if ((string)parameter == "lineheight")
                    return res * 0.8;
                else
                    return res * 0.1;
            }

            else
                return res;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
	}
}
